package cn.maple.transactionMessge;


import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class TransactionMessageProducer {


    public static void main(String[] args) throws Exception {
        // 实例化消息生产者Producer
        TransactionMQProducer mqProducer = new TransactionMQProducer("TransactionMessage-producer");
        //配置路由
        mqProducer.setNamesrvAddr("localhost:9876");
        // 监听
        mqProducer.setTransactionListener(new MyTransactionListener());
        // 启动
        mqProducer.start();
        //消息
        Message message = new Message("TransactionMessage", "producer", "producerproducerproducer".getBytes(StandardCharsets.UTF_8));
        // 消息推送
        TransactionSendResult jjk = mqProducer.sendMessageInTransaction(message, "producerproducerproducer");
        System.out.println("===============TransactionMessageProducer=================");
        // 关闭生产者
        mqProducer.shutdown();



    }
}

